-
Notifications
You must be signed in to change notification settings - Fork 19.2k
feat(langchain_v1): on_tool_call interceptor (wip) #33290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial pass, just looking at types
) | ||
|
||
|
||
def _infer_retriable_types( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't actually need this right?
"""Response returned from on_tool_call handler after tool execution. | ||
|
||
The action field determines control flow: | ||
- "return": Handler completed successfully, use result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i've been debatinc continue vs. return
def __post_init__(self) -> None: | ||
"""Validate that required fields are present based on action.""" | ||
if self.action == "return" and self.result is None: | ||
msg = "action='return' requires a result" | ||
raise ValueError(msg) | ||
if self.action == "raise" and self.exception is None: | ||
msg = "action='raise' requires an exception" | ||
raise ValueError(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like
from typing import Literal
from typing_extensions TypedDict, NotRequired
class _ContinueToolCallResponse(TypedDict):
"""Response when tool execution completed successfully.
Attributes:
action: Always "continue" to indicate normal flow.
result: ToolMessage or Command to be processed.
exception: Optional exception for logging purposes.
"""
action: Literal["continue"]
result: ToolMessage | Command
exception: NotRequired[Exception]
class _RaiseToolCallResponse(TypedDict):
"""Response when tool execution wants to propagate an exception.
Attributes:
action: Always "raise" to indicate exception propagation.
exception: The exception to be raised.
"""
action: Literal["raise"]
exception: Exception
ToolCallResponse = _ContinueToolCallResponse | _RaiseToolCallResponse
@@ -100,6 +98,61 @@ def my_tool(x: int) -> str: | |||
) | |||
|
|||
|
|||
@dataclass() | |||
class ToolRequest: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToolCallRequest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more fun thoughts :)
return (Exception,) | ||
|
||
|
||
class RetryMiddleware(AgentMiddleware): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class RetryMiddleware(AgentMiddleware): | |
class ToolRetryMiddleware(AgentMiddleware): |
close: #33329 |
Still WIP:
Changes: